<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>客户信息列表</title>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="/wanda/Scripts/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="/wanda/Scripts/bootstrap.min.js"></script>

<link rel="stylesheet" type="text/css"
	href="/wanda/Scripts/normalize.css" />
<link rel="stylesheet" type="text/css"
	href="/wanda/Scripts/font-awesome-4.2.0/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="/wanda/Scripts/demo.css" />
<link rel="stylesheet" type="text/css"
	href="/wanda/Scripts/component.css" />
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet"
	href="/wanda/Scripts/jqurey.ui/ui-lightness/jquery-ui-1.8.21.custom.css" />
<link type="text/css" rel="stylesheet"  
	href="/wanda/Scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css" />

<script type="text/javascript"
	src="/wanda/Scripts/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript"
	src="/wanda/Scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript"
	src="/wanda/Scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript"
	src="/wanda/Scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" href="/wanda/Scripts/bootstrap.min.css" />

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="stylesheet" href="/wanda/Scripts/bootstrap-theme.min.css" />
<script type="text/javascript">

   function ajaxUpdate123(data){
	      //data  后台传过来的所有的单元的信息
           var tfloor = $(data)[0].wdHtBuild.floorCount;  //单元数
           var  tunit_number= $(data)[0].wdHtBuild.floorCount;//楼层数
           //传递到下面  不知道为什么这么多的js块
           $('#floorrr').val(tfloor);
           
           if(tunit_number>2){
           $("#list4").attr("width","100%");
           }
           var $table = $("#lift");
           
           var tr="";
           for(var i=0;i<tunit_number;i++){
        	   tr=tr+"<tr ><td width='200px'> <input style='width:100%' value="+(i+1)+" type='text'  name='floor_number'></td></tr>";
           }
           $table.append($(tr));
           for(var a=0;a<$(data).size();a++){
        	   $("#list4 tr:first").append("<td><input style='width: 100%' value="+$(data)[a].unitId+" type='hidden' name='unit'/><input style='width: 100%' value="+$(data)[a].unitCode+" type='text' name='unitCode'/></td>");
        	   $("#list4 tr:gt(0)").append("<td><input style='width: 100%' type='text' value='2' name='hushu'/></td>");
           }
          
           //$('#myModal').modal('hide');   
        
  } 
	function sendMassage(m) {
		  var floor_numbers = document.getElementsByName("floor_number");
		  var haoma = document.getElementsByName("haoma");
	    	var val = $("#lift tr").eq(m).children('td').each(function(){
	    	   $(this).children('span').eq(1).text(floor_numbers[m].value);
	    	  });
	    	var $trList = $("#lift");
	    	$trList.attr("width","100%");
	} 
	function sendMassageRow(h) {
		var row = "#row"+h;
		var va = $(row);
		var a=0;
	    $("#lift tr").each(function(){
	    	  $(this).children('td').eq(h+2).children("span").eq(2).text(va.val());
	     });
	    	var $trList = $("#lift");
	    	$trList.attr("cellpadding",0);
	} 
	
</script>
<script type="text/javascript">
function unique(arr) {
	  var result = [], hash = {};
	  for (var i = 0, elem; (elem = arr[i]) != null; i++) {
	    if (!hash[elem]) {
	      result.push(elem);
	      hash[elem] = true;
	    }
	  }
	  return result;
	}
var right;
function ajaxDelete(n) {
	var trs = $("#lift tr");
	if (n == '全部') {
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
				console.log($(data[j]).text());
				$(data[j]).find("input").remove();
					$(data[j]).append("<input type='checkbox' checked = true name='resour'>");
			}

		}
	} else if (n == '清空') {
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
				console.log($(data[j]).text());
				$(data[j]).find("input").remove();
					$(data[j]).append("<input type='checkbox' name='resour'>");
			}

		}
	} else {
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
				console.log($(data[j]).text());
				$(data[j]).find("input").remove();
				if (n == $(data[j]).text()) {
					$(data[j]).append("<input type='checkbox' checked = true name='resour'>");
				} else {
					$(data[j]).append("<input type='checkbox' name='resour'>");
				}

			}

		}
	}
}
function util(){
	var haoma = document.getElementsByName('haoma');
	for(var x=0 ;x<haoma.length;x++){
        if((haoma[x].value).length>1){
        	 haoma[x].value = haoma[x].value.substring(0,1);
        }			
}
	var floor_number = document.getElementsByName('floor_number');
	for(var y=0 ;y<floor_number.length;y++){
        if((floor_number[y].value).length>1){
        	floor_number[y].value = floor_number[y].value.substring(0,1);
        }			
}
}
function ajaxNumber(n) {
	var trs = $("#lift tr");
	if (n == '楼层+号码') {
		//util();
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
			$(data[j]).children('span').eq(0).hide();
			$(data[j]).children('span').eq(1).remove('span');
			$(data[j]).children('span').eq(2).remove('span');
			$(data[j]).children('span').eq(1).remove('span');
			$(data[j]).append("<span >"+(i+1)+"</span>0<span>"+(j-1)+"</span>");
			}
		}
	} else if (n == '号码+楼层') {
		//util();
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
			$(data[j]).children('span').eq(0).hide();
			$(data[j]).children('span').eq(1).remove('span');
			$(data[j]).children('span').eq(2).remove('span');
			$(data[j]).children('span').eq(1).remove('span');
			$(data[j]).append("<span>"+(j-1)+"</span>0<span >"+(i+1)+"</span>");
			}
		}
	} else {
		for (var i = 0; i < trs.length; i++) {
			var data = trs.eq(i).children();
			for (var j = 2; j < data.length; j++) {
				console.log($(data[j]).text());
				$(data[j]).find("input").remove();
				if (n == $(data[j]).text()) {
					$(data[j]).append("<input type='checkbox' checked = true name='resour'>");
				} else {
					$(data[j]).append("<input type='checkbox' name='resour'>");
				}

			}

		}
	}
}
</script>
<script type="text/javascript">  
    function ajaxInsert(){ 
    	var hushus = document.getElementsByName("hushu");
    	var unit = document.getElementsByName("unit");
    	var  tunit_number= $("#floorrr").val();   //单元数
    	var $list4 = $("#list4");
    	var haoma=0;
    	var haomatr="<tr><td>号码</td>";
    	var huxing = "<tr><td>户型</td>";
    	var $trList = $("#lift");
    	$trList.attr("width","100%");
       //修改单元是不一致
    	for(var b=0;b<hushus.length;b++){
    		var huval = hushus[b].value;
    		haoma = haoma+(parseInt(hushus[b].value));
    	}
    	for(var u=0;u<unit.length;u++){
    		$(unit[u]).parent().attr("colspan",hushus[u].value);
    	}
    
    	for(var h=0;h<haoma;h++){
    		haomatr = haomatr +"<td><input  type='text'  value="+(h+1)+" id=row"+h+" oninput=sendMassageRow("+h+") style='width: 100%' name='haoma'></td>"
    		huxing = huxing +"<td><select  style='width: 100%'  onchange='ajaxSelect(this.options[this.options.selectedIndex].text,"+(h+2)+")'><option value='两房两厅'>两房两厅</option><option value='三房两厅'>三房两厅</option><option value='三房一厅'>三房一厅</option></select></td>"
        
    	}
    	haomatr = haomatr+"</tr>";
    	$("#lift").empty();
        for (var i=0; i<tunit_number; i++) {
        	
         	var rowdan="<tr><td width='5.9%'> <input style='width:100%;height:100%' value="+(i+1)+" type='text' oninput=sendMassage("+i+") name='floor_number' ></td>";
         	for(var j=0;j < parseInt(haoma)+1; j++){
            	if(j==0){
        	       rowdan =rowdan+"<td  width='6%'><select  style='width: 100%'  onchange='ajaxSelectrow(this.options[this.options.selectedIndex].text,"+(i)+")'><option value='两房两厅'>两房两厅</option><option value='三房两厅'>三房两厅</option><option value='三房一厅'>三房一厅</option></select></td>";	
        		}else{
        			rowdan = rowdan+"<td width='"+(935/parseInt(haoma))+"px'><span>两房两厅</span></td>";	
        		}
            	
               }      
        	  rowdan =rowdan+"</tr>";	
        	$trList.append($(rowdan));
    	}
        var hushurow = $("#rowhushu").remove();;
    	  $list4.append($(haomatr));
    	  $list4.append($(huxing));
     } 
    function ajaxSelect(v,n){  
    	var str = "<span >"+v+"</span>"
    	 var te = "<input type='checkbox' checked='true' name='resour'>";
     	$("#lift tr").each(function(){
          var data = $(this).children('td').eq(n)
          for(var i =0;i<data.length;i++){
        	  if(data[i].lastChild.type=="checkbox"){
        		  if(data[i].lastChild.checked==true){
        		  $(data).eq(i).html(str);
                  $(data).eq(i).append($(te));
        		  }
        	  }else{
        		  $(data).eq(i).html(str);
        	  }
          }
        });
    } 
</script>
<script type="text/javascript">
    function ajaxSelectrow(v,m){
      var str = "<span >"+v+"</span>"
     	var $datalen = $("#lift tr").eq(m).children('td');
        var te = "<input type='checkbox' checked='true' name='resour'>";
     	for(var i=2;i<$datalen.size();i++){
     		if($datalen[i].lastChild.type=="checkbox"){
     		if($datalen[i].lastChild.checked==true){
     			$datalen.eq(i).html(str);
     	    	$datalen.eq(i).append($(te));
     			  }
     		}else{
     			$datalen.eq(i).html(str);
     		}
     	}
    }
   function roomBase (){
	   var buildUpArea=$("#buildUpArea").val();
	   var innerArea=$("#innerArea").val();
	   var innerPrice=$("#innerPrice").val();
	   var unitPrice=$("#unitPrice").val();
	   
	  
	   
	   
		var trs = $("#lift tr");
		var trslist = $("#list4 tr").eq(0).children();
		var buildarr= new Array(trslist.size());
		var abc = 0;
		for(var x=0;x<trslist.size();x++){
			var colspanval = trslist.eq(x).attr('colspan');
			for(var y=0;y<colspanval;y++){
				buildarr[abc]=trslist.eq(x).children().val();
				//alert(abc+"===="+trslist.eq(x).children().val());
				abc++
			}
		}
		
		var aabbba=null;
		var arr=new Array();
		for (var i = 0; i < trs.length; i++) {
			var object;  
			var data = trs.eq(i).children();			
				for (var j = 2; j < data.length; j++) {
					object = new Object();
					var huxing = $(data[j]).children('span').eq(0).text();
					var f1 = $(data[j]).children('span').eq(1).text();
					var f2 = $(data[j]).children('span').eq(2).text();
					var number= f1+"0"+f2;
					
					 //户型id  只好写死  //前台我又不会写 tmd
					if(huxing=='两房两厅')
					{
						object.apartmentLayoutId='ca941308-35d6-11e6-b073-1008b171f622';
					}
					else if(huxing=='三房两厅')
					{
						object.apartmentLayoutId='cecdb7e2-35d6-11e6-b073-1008b171f622';
					}
					else if(huxing=='三房一厅')
					{
						object.apartmentLayoutId='aa2238a3-35d6-11e6-b073-1008b171f622';
					}
					//房间编号
					object.roomCode=number;
					//不知道是什么
					object.lid=right;
					//单元id
					object.unitId = buildarr[j-2];
					//所属楼层
					object.floor=i+1;
					//项目id
					object.projectId=$("#project").val();
					//楼栋id
					object.buildId=$("#buildId").val();
					//默认状态3===未开盘
				    object.state=3;
					//用途id 只好写死
					object.purposeId='001b4414-35d8-11e6-b073-1008b171f622';
				   //建筑面积
				   object.buildUpArea=buildUpArea;
				   //套内面积
				   object.innerArea=innerArea;
				   //套内价格
				   object.innerPrice=innerPrice;
				   //建筑价格
				  object.unitPrice=unitPrice;
					arr.push(object);
				}
		}
		
		//alert(JSON.stringify(arr));
		 $.ajax({
			// url:"../qt/build/addRoomredis.do",
			 url:"/wanda/room/addRoomredis.do",
			  type:"POST",
		      dataType: "json",
		      contentType:'application/json',
		      data:JSON.stringify(arr),
			 success:function(data){
				  // alert(1);
				 window.location.href='/wanda/room/list.do?currentPage=1&rowsOfpage=15';
			 }
		 });	
   } 
</script>

<script type="text/javascript">
//获取楼栋信息
function getBuild()
{
    var projectId = $("#project").val();	
    $("#buildId").empty();
    $("#buildId").append("<option value=''>请选择</option>");
    $.ajax({
    	   url:"/wanda/unit/getBuild.do",
    	   data:{"projectId":projectId},
    	   type:"post",
    	   dataType: "json",
    	   success:function(data){
    		  // $("#buildId").empty();
			   $(data).each(function(){
  				 $("#buildId").append("<option value="+this.buildId+">"+this.buildName+"</option>");
			   });
    	   },
    	   error:function()
    	      {
    		   alert("程序错误！！！"); 
    	      }
          });
}


function jiegou()
{
	var buildId = $("#buildId").val();
	//获取单元信息
	  $.ajax({
	  	   url:"/wanda/unit/unitList.do",
	  	   data:{"buildId":buildId},
	  	   type:"post",
	  	   dataType: "json",
	  	   success:function(data){
	  		       //楼层数
	  		      //alert($(data)[0].wdHtBuild.floorCount+"楼层");
				  //传过去data  进行处理
				  ajaxUpdate123(data);
	  	   },
	  	   error:function()
	  	      {
	  		   alert("程序错误！！！"); 
	  	      }
	        });
}
</script>
</head>
<body>
	<div id="gridPager"></div>
	<div class="yboxwidth boxcenter ybox01" style="width: 100%">
		<div class="ybox09" style="width: 100%">
			<h1 align="center" style="size: 5">房间批量生成</h1>
		</div>

		<div class="ybox02" style="width:100%">
			<table width="1235px" border="0" cellspacing="0" cellpadding="0"
				class="margb4"> 
				<tr>
							<dl>
								<table border="0" cellspacing="0" cellpadding="0" class="ybox07table" width="100%">
									<tr align="left">
									
									<td><span style="cursor: pointer;">楼盘： 
									    <select id="project" onchange="getBuild()">
							     <option value='-1'>请选择</option>
									    <c:forEach items="${projectList}" var="project">
													  <option value='${project.projectId}'>${project.projectName}</option>
				                        </c:forEach>
									</select></span></td>
									 <td>&nbsp;</td>
									<td><span style="cursor: pointer;">楼栋：
									    <select id="buildId">
							            <option value='-1'>请选择</option>
									    </select></span></td>
									   <td>&nbsp;</td>
									   
									   <td class="ybox07td1"><img src="/wanda/images/xiugai.png" /></td>
									<td><span style="cursor: pointer;" onclick="jiegou()">生成基本结构</span></td>
									
									 <td>&nbsp;&nbsp;&nbsp;<img
											src="/wanda/images/op4_0.gif" />&nbsp;&nbsp;&nbsp;</td>
										
										<td class="ybox07td1"><img src="/wanda/images/op4_3.gif"/></td>
										<td><span style="cursor: pointer;">户型：<select id="huxing"
												onchange="ajaxDelete(this.options[this.options.selectedIndex].text)">
													<option value='清空'>清空</option>
													<option value='全部'>全部</option>
													<option value='两房两厅'>两房两厅</option>
													<option value='三房两厅'>三房两厅</option>
													<option value='三房一厅'>三房一厅</option>
											</select></span></td>
											<td class="ybox07td1"><img src="/wanda/images/op4_5.gif"/></td>
											<td><span style="cursor: pointer;">房间号规则：<select
												onchange="ajaxNumber(this.options[this.options.selectedIndex].text)">
													 <option value='号码+楼层'>号码+楼层</option>
													<option value='楼层+号码'>楼层+号码</option>
											</select></span></td>
											
											<td class="ybox07td1"><img src="/wanda/images/op4_1.gif" /></td>
										<td><span style="cursor: pointer;" onclick="ajaxInsert()">生成房间</span></td>
										<td>&nbsp;&nbsp;&nbsp;<img
											src="/wanda/images/op4_0.gif" />&nbsp;&nbsp;&nbsp;</td>
										<td>实际面积：<input id="buildUpArea" style="width: 25px; height: 15px"/></td>
										<td>使用面积：<input id="innerArea" style="width: 25px; height: 15px"/></td>
										<td>套内单价：<input id="innerPrice" style="width: 25px; height: 15px"/></td>
										<td>建筑单价：<input id="unitPrice" style="width: 25px; height: 15px"/></td>
										
											 <td>&nbsp;&nbsp;</td>
											<td class="ybox07td1"><img src="/wanda/images/op4_6.gif" /></td>
										<td><span style="cursor: pointer;" onclick="roomBase()">确认提交</span></td>
										<td class="ybox07td2" width="20%"></td>
									</tr>
								</table>
							</dl>
						</div>
						<table width="1235px" border="1" cellpadding="0" cellspacing="1"
							class="ybox06table" id="list4">
							<tr>
								<td width="100px" rowspan="4">楼层名称</td>
								<td width="100px">单元</td>
							</tr>
							<tr id="rowhushu">
								<td width="100px">户数</td>
							</tr>
						</table>
						<table id="lift" border="1">
						</table>
				</tr>
				<tr> 
					<td class="ybox03td7"></td>
					<td class="ybox03td8"></td>
					<td class="ybox03td9"></td>
				</tr>
			</table>
			<input type="hidden" id="floorrr"/>
		</div>
	</div>
</body>